package mr

import (
	"fmt"
	"log"
	"time"
)

type logger struct {
	name string
}

// returns a new logger with name.
func newLogger(name string) logger {
	return logger{name: name}
}

func (w logger) Write(bytes []byte) (n int, err error) {
	timeString := time.Now().Format("2006/01/02 15:04:05 -0700")
	return fmt.Printf("[%s][%s] %s", timeString, w.name, string(bytes))
}

// replace the default logger.
func setupLog(name string) {
	log.SetFlags(log.Lshortfile)
	log.SetOutput(newLogger(name))
}
